﻿using System;
using NUnit.Framework;

namespace fluentvaly.Tests.ValidationStatementTests
{
    [TestFixture]
    public class ToStringFixture
    {
        private const string ERROR_MESSAGE = "Error message";

        [Test]
        public void ToString_BasicExpressionGiven_MessageWithNoIfRendered()
        {
            var validationStatement = new MemberValidator<UserTestObject, string>(u => u.Password, ERROR_MESSAGE, InvalidationReasons.Missing);

            validationStatement.Is(pass => pass.Length > 8);

            Console.WriteLine(((IValidationStatement)validationStatement).ToString());
        }

        [Test]
        public void ToString_ConplexExpressionGiven_MessageWithNoIfRendered()
        {
            var validationStatement = new MemberValidator<UserTestObject, string>(u => u.Password, ERROR_MESSAGE, InvalidationReasons.Missing);

            validationStatement.Is((user, pass) => pass.Length > user.PasswordConfirmation.Length);

            Console.WriteLine(((IValidationStatement)validationStatement).ToString());
        }

        [Test]
        public void ToString_BasicExpressionGiven_MessageWithIfRendered()
        {
            var validationStatement = new MemberValidator<UserTestObject, string>(u => u.Password, ERROR_MESSAGE, InvalidationReasons.Missing);

            validationStatement.Is(pass => pass.Length > 8).If(u => string.IsNullOrEmpty(u));

            Console.WriteLine(((IValidationStatement)validationStatement).ToString());
        }

        [Test]
        public void ToString_ExternalValidationMethodGiven_MessageWithMethodNameRendered()
        {
            var validationStatement = new MemberValidator<UserTestObject, string>(u => u.Password, ERROR_MESSAGE, InvalidationReasons.Missing);

            validationStatement.Is(p =>PasswordValid(p)).If(u => string.IsNullOrEmpty(u));

            Console.WriteLine(((IValidationStatement)validationStatement).ToString());
        }

        private bool PasswordValid(string password)
        {
            return true;
        }
    }
}
